#include "enemyplane.h"
#include"config.h"

EnemyPlane::EnemyPlane()
{
    m_enemy.load(ENEMY_PATH);

    m_X=0;
    m_Y=0;

    m_Free=true;
    m_Speed=ENEMY_SPEED;

    m_Rect.setWidth(m_enemy.width());
    m_Rect.setHeight(m_enemy.height());
    m_Rect.moveTo(m_X,m_Y);

    m_recorder=0;
}

void EnemyPlane::updatePosition()
{
    if(m_Free)
    {
        return;
    }
    m_Y+=m_Speed;
    m_Rect.moveTo(m_X,m_Y);

    if(m_Y >=GAME_HEIGHT)
    {
        m_Free=true;
    }
}

void EnemyPlane::shoot()
{
    m_recorder++;
    if(m_recorder<BULLET2_INTERVAL)
    {
        return;
    }
    m_recorder=0;
    for(int i=0;i<BULLET2_NUM;i++)
    {
        if(m_bullet2s[i].m_Free)
        {
            m_bullet2s[i].m_Free=false;
            m_bullet2s[i].m_X=m_X+m_Rect.width()*0.5-10;
            m_bullet2s[i].m_Y=m_Y+25;
            break;
        }
    }

}
